package adapters;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import java.util.List;

import beans.OperateGoodsDetailsBean;
import butterknife.BindView;
import custom.BaseRecyclerAdapter;

/**
 * Created by Administrator on 2018/5/22.
 */

public class CommonStateErrorAdapter extends BaseRecyclerAdapter<CommonStateErrorAdapter.CommonErrorViewHolder> {
    private Context mContext;
    private LayoutInflater inflater;
    private List<OperateGoodsDetailsBean.DataBean> list;
    private OnClickListener onClickListener;

    public CommonStateErrorAdapter(Context mContext, List<OperateGoodsDetailsBean.DataBean> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public CommonErrorViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        CommonErrorViewHolder viewHolder = new CommonErrorViewHolder(inflater.inflate(R.layout.adapter_common_error, parent, false));
        return viewHolder;
    }

    public void addData(List<OperateGoodsDetailsBean.DataBean> list) {
        if (list != null) {
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }

    @Override
    public void onBindViewHolder(final CommonErrorViewHolder viewHolder, final int position) {
        OperateGoodsDetailsBean.DataBean bean = list.get(position);
        viewHolder.tvCabinetNumber.setText(String.valueOf(bean.getSelectCabinet()));
        viewHolder.tvName.setText(bean.getGoodName());
        viewHolder.tvSpecification.setText(bean.getSpecification());
        viewHolder.tvSupplier.setText(bean.getManufacturer());
        viewHolder.tvCount.setText(String.valueOf(bean.getNumber()));
        viewHolder.tvUnit.setText(bean.getGoodsUnit());
        if (bean.getStatus() == 1) {
            viewHolder.tvState.setText("未验收");
        } else if (bean.getStatus() == 2) {
            viewHolder.tvState.setText("已验收");
        } else if (bean.getStatus() == 3) {
            viewHolder.tvState.setText("已放入");
        } else if (bean.getStatus() == 4) {
            viewHolder.tvState.setText("已取出");
        } else if (bean.getStatus() == 5) {
            viewHolder.tvState.setText("已使用");
        } else if (bean.getStatus() == 6) {
            viewHolder.tvState.setText("已退货");
        }else if (bean.getStatus() == 12) {
            viewHolder.tvState.setText("未归审批");
        }
        viewHolder.tvState.setTextColor(Color.RED);
        if (position % 2 == 0) {
            viewHolder.linearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.partLineBackground));
        } else {
            viewHolder.linearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class CommonErrorViewHolder extends BaseRecyclerAdapter.BaseViewHolder {
        @BindView(R.id.tv_adapter_common_error_cabinet_number)
        TextView tvCabinetNumber;
        @BindView(R.id.tv_adapter_common_error_name)
        TextView tvName;
        @BindView(R.id.tv_adapter_common_error_specification)
        TextView tvSpecification;
        @BindView(R.id.tv_adapter_common_error_supplier)
        TextView tvSupplier;
        @BindView(R.id.tv_adapter_common_error_count)
        TextView tvCount;
        @BindView(R.id.tv_adapter_common_error_unit)
        TextView tvUnit;
        @BindView(R.id.tv_adapter_common_error_state)
        TextView tvState;
        @BindView(R.id.ll_common_error_title)
        LinearLayout linearLayout;

        public CommonErrorViewHolder(View itemView) {
            super(itemView);
        }
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        //        void onShowDetailSpecification(int position, TextView view);
        void onShowDetail(int position, TextView view, int xOffWidth);
        //        void onShowDetailSupplier(int position, TextView view);
    }
}
